package com.webwork.common.dao;

/**
 * 分页类
 *
 */
public class Paging {

	/**
	 * 当前页
	 */
	private int currPage = 1;

	/**
	 * 每页最大记录数
	 */
	private int pageSize = 10;

	/**
	 * 总记录数
	 */
	private int count = 0;

	public Paging(int page, int size) {
		this.currPage = page;
		this.pageSize = size;
	}

	public Paging() {
		super();
	}

	public int getCurrPage() {
		return currPage;
	}

	public void setCurrPage(int currPage) {
		this.currPage = currPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	/**
	 * 总页数
	 * 
	 * @return
	 */
	public int getTotalPage() {
		return (count / pageSize) + (count % pageSize == 0 ? 0 : 1);
	}

	/**
	 * 是否第一页
	 * 
	 * @return
	 */
	public boolean isFirst() {
		return currPage == 1;
	}

	/**
	 * 是否最后一页
	 * 
	 * @return
	 */
	public boolean isLast() {
		return currPage >= getTotalPage();
	}

	/**
	 * 上一页页码
	 * 
	 * @return
	 */
	public int getPre() {
		if (isFirst()) {
			return 1;
		}
		return currPage - 1;
	}

	/**
	 * 下一页页码
	 * 
	 * @return
	 */
	public int getNext() {
		if (getTotalPage() > 0 && currPage + 1 > getTotalPage())
			return getTotalPage();
		return currPage + 1;
	}

}
